// pages/user/company/companyTrends/companyTrends.js
const common = require('../../../utils/util.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        type: null,
        userInfo: null,
        companyTrends: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            type: options.type
        })
        this.getUserInfo()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        common.refresh()
        setTimeout(function () {
            wx.stopPullDownRefresh()
        }, 2000)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    getUserInfo: function () {
        const that = this
        let data = {}
        common.post('User/user_info', data).then(function (res) {
            if (res.code == 204) {
                return
            } else {
                that.setData({
                    userInfo: res
                })
                that.getCompanyTrends()
            }
        }).catch(function (e) {})
    },

    getCompanyTrends: function () {
        wx.showLoading({
            title: '加载中'
        })
        const that = this
        let data
        if (this.data.type == 'manager') {
            data = {
                client: 2,
                store_id: this.data.userInfo.store_id,
                filiale_id: this.data.userInfo.filiale_id,
                people_type: 1,
                paramter: 1
            }
        } else if (this.data.type == 'filiale') {
            data = {
                client: 2,
                store_id: this.data.userInfo.store_id,
                filiale_id: this.data.userInfo.filiale_id,
                people_type: 2,
                paramter: 1
            }
        } else if (this.data.type == 'shop') {
            data = {
                client: 2,
                store_id: this.data.userInfo.store_id,
                filiale_id: this.data.userInfo.filiale_id,
                people_type: 3,
                paramter: 1
            }
        }
        common.post('Data/get_user_dynamic', data).then(function (res) {
            wx.hideLoading()
            if (res.code == 204) {
                return
            }
            that.setData({
                companyTrends: res
            })
        }).catch(function (e) {})
    }
})